# -*- coding: utf-8 -*-
#打包成zip文件

import zipfile
import os
import fnmatch
import os.path
import re

includes = ['*'] # for files only
excludes = ['*.lib', '*.obj', "*.tlog", "*.cache", "*.lastbuildstate", "*.log", "*.idb", "*.pdb", "*.res", "*.ilk"] # for dirs and files

# transform glob patterns to regular expressions
includes = r'|'.join([fnmatch.translate(x) for x in includes])
excludes = r'|'.join([fnmatch.translate(x) for x in excludes]) or r'$.'

zf = zipfile.ZipFile('archive.zip','w',zipfile.ZIP_DEFLATED)

startdir = os.path.abspath(".")

def packDir(d, arcname):
	os.chdir(startdir)
	os.chdir(d)
	for root, dirs, files in os.walk('.'):
	    # exclude/include files
	    files = [os.path.join(root, f) for f in files]
	    files = [f for f in files if not re.match(excludes, f)]
	    files = [f for f in files if re.match(includes, f)]

	    for fname in files:
	    	print(fname)
	        zf.write(fname, arcname+"/"+fname)


packDir("Debug.win32", "Debug.win32")
packDir("../../../res", "Debug.win32/res")
packDir("../../../src", "Debug.win32/src")

zf.write("C:\\Windows\System32\msvcp110d.dll", "Debug.win32/msvcp110d.dll")
zf.write("C:\\Windows\System32\msvcr110d.dll", "Debug.win32/msvcr110d.dll")

import _winreg

key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"Software\ZeroC\Ice 3.5.0")
value, type = _winreg.QueryValueEx(key, "InstallDir")

zf.write(os.path.join(value, "bin/vc110/ice35d.dll"), "Debug.win32/ice35d.dll")
zf.write(os.path.join(value, "bin/vc110/iceutil35d.dll"), "Debug.win32/iceutil35d.dll")
zf.write(os.path.join(value, "bin/vc110/glacier235d.dll"), "Debug.win32/glacier235d.dll")
zf.write(os.path.join(value, "bin/vc110/bzip2d.dll"), "Debug.win32/bzip2d.dll")

zf.close()
